package com.example.springboot.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot.demo.entity.User;
import com.example.springboot.demo.mapper.UserMapper;
import com.example.springboot.demo.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public int update(User user) {
        //此处的save与update为mybatis-plus封装好的
        return user.getId() != null ? userMapper.update(user) : userMapper.insert(user);
    }

    @Override
    public List<User> listUser(Integer pageNum, Integer pageSize, String username) {
        if (pageNum != null && pageSize != null) {
            pageNum = (pageNum - 1) * pageSize;
        }
        return userMapper.listUser(pageNum, pageSize, username);
    }

    @Override
    public int deleteUser(int id) {
        return userMapper.deleteUser(id);
    }

    @Override
    public int countUser() {
        return userMapper.countUser();
    }
}
